package com.sali.utils.loadbalance;

import org.springframework.cloud.client.ServiceInstance;

import java.util.List;

/**
 * @description: 轮询算法
 * @author: zhang hang
 * @date: 2022/7/18 20:41.
 * @version: 1.0
 */
public class RoundRobin implements ILoadBalanceAlgorithm {

    private static Integer pos = 0;

    @Override
    public ServiceInstance algorithmDetail(List<ServiceInstance> instances) {
        if (pos >= instances.size()) {
            pos = 0;
        }
        ServiceInstance serviceInstance = instances.get(pos);
        pos++;
        return serviceInstance;
    }
}
